package com.cbs.module.friend.sort;

import com.cbs.module.friend.entity.FriendRelation;
import com.cbs.module.friend.entity.FriendRequest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by broche on 1/26/16.
 */
public class Sorter {
    public static List<FriendRelation> sortFriendRelation(List<FriendRelation> friends) {
        List<FriendRelation> res = new ArrayList<>();
        FriendRelation[] arr = friends.toArray(new FriendRelation[friends.size()]);
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i].getNicknamespell().compareTo(arr[j].getNicknamespell()) > 0) {
                    FriendRelation tfriend = arr[j];
                    arr[j] = arr[i];
                    arr[i] = tfriend;
                }
            }
        }
        Collections.addAll(res, arr);
        return res;
    }

    public static List<FriendRequest> sortFriendRequest(List<FriendRequest> friendRequests) {
        List<FriendRequest> res = new ArrayList<>();
        FriendRequest[] arr = friendRequests.toArray(new FriendRequest[friendRequests.size()]);
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i].getNicknamespell().compareTo(arr[j].getNicknamespell()) > 0) {
                    FriendRequest trequest = arr[j];
                    arr[j] = arr[i];
                    arr[i] = trequest;
                }
            }
        }
        Collections.addAll(res, arr);
        return res;
    }
}
